﻿using System.Configuration;
using System.IO;
using CI.Models.Data;
using log4net;

namespace XmlModelPackager
{
    public class GraphcisXmlGenerator : XmlGeneratorBase, IXmlGenerator
    {
        private readonly ILog _logger = LogManager.GetLogger(typeof(GraphcisXmlGenerator));

        public GraphcisXmlGenerator() : base(new FileInfo("graphics.xml"),"Graphics")   
        {}

        protected TyrannisDataContext GetDataContext()
        {
            return new TyrannisDataContext(ConfigurationManager.ConnectionStrings["TyrannisDB"].ConnectionString);
        }

        public void GenerateXml()
        {
            using (var ctx = GetDataContext())
            {
                var graphics = ctx.eveGraphics;

                foreach(var graphic in graphics)
                {
                    _logger.DebugFormat("Processing {0}:{1}",graphic.graphicID,graphic.icon);

                    BeginElement("Graphic");

                    WriteAttributes(graphic, "graphicID", "url3D", "urlWeb", "description", "published", "obsolete",
                                    "icon", "urlSound", "explosionID");

                    EndElement();
                }
            }
        }
    }
}